<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>阻止元素默认行为</title>
</head>

<body>
  <form action="">
    <input type="submit" value="提交">
  </form>

  <a href="https://www.baidu.com">百度</a>
  <script>
    // submit  表单提交事件
    document.querySelector('form').addEventListener('submit', function (e) {
      e.preventDefault()
    })

    document.querySelector('a').addEventListener('click', function (e) {
      e.preventDefault()
    })
  </script>
</body>

</html>